package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.domain.Orders;
import com.itheima.reggie.dto.OrderDto;
import com.itheima.reggie.service.OrdersService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;



@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders){

        ordersService.submit(orders);

        return R.success(null);
    }

    //查看订单
    @GetMapping("/userPage")
    public R userPage(int page,int pageSize){

      Page<OrderDto> p =  ordersService.findPage(page,pageSize);

      return R.success(p);
    }

    //后台订单明细表分页查询
    @GetMapping("/page")
    public R page(int page, int pageSize, String number, LocalDateTime beginTime, LocalDateTime endTime){

        Page<Orders> list = ordersService.findPageOrders(page,pageSize,number,beginTime,endTime);

        return R.success(list);
    }

    //修改订单状态
    @PutMapping
    public R delivery(@RequestBody Orders orders){

        ordersService.updateStatus(orders);

        return R.success(null);
    }
}
